<html>
<head>
<script language="Javascript" src="../gamelib/gamelib_core.js"></script>
<script language="Javascript" src="../gamelib/gamelib_sprites.js"></script>
<script language="Javascript" src="../gamelib/gamelib_mouse.js"></script>
<script language="Javascript">

var number_of_tiles=12//*18;
var mymouse=null;
var mysprite=new Array();

for(n=0;n<6;n++) Gl_preloader("../images/msi"+n+".gif");	// preload images to cache

function init(){
	Sp_linuxcompatible=true;
	for(n=0;n<number_of_tiles;n++) mysprite[n]=new Sp_Sprite();
	randomize_tiles();
	Sp_xoffset=40;					// all sprites relative to position
	Sp_yoffset=40;					// 100,100 on screen

	var spx=0;
	for(n=0;n<Sp_totalsprites;n++){
		mysprite[n].setSpeed(0);			// give it a speed of 0.
		mysprite[n].bounces=true;			// I want them to bounce!
		mysprite[n].setXYdegs(Math.floor(Math.random()*360));
		mysprite[n].setXlimits(0,400);			// limit its x movement.
		mysprite[n].setYlimits(0,300);			// limit its y movement.
		mysprite[n].moveTo(spx*32,100);			// initial position.

		mysprite[n].onmouseover="colour_change("+n+",5)";// give sprite a mouseover event
		mysprite[n].onmouseout="colour_change("+n+",0)";// give sprite a mouseout event
		mysprite[n].onclickdown="start_stop("+n+")";	// give sprite a clickdown event
								// onclickup isn't used in this example
		mysprite[n].makeDraggable();			// make draggable!
		mysprite[n].switchOn();				// switch the sprite on!
		spx++;
	}
	mymouse=Ms_initmouse();			// start the mouse handler...
	Gl_scrollbars("no");			// no scrollbars...
	Gl_start();				// Start the engine!
}

function colour_change(a,b){	// the mouseover/mouseout events use this to set the sprite's colour
				// the button image has 6 frames of different coloured buttons, I'm
				// just altering the frame...
	mysprite[a].setFrame(b);
}

function start_stop(a){		// sets sprite's speed. if it's currently 0, sets it to 4 and vice versa.
	if(mysprite[a].speed>0) mysprite[a].setSpeed(0);
	else mysprite[a].setSpeed(8)
}

function randomize_tiles(){	// gives sprites random images (same image, different frames initially)
	for(n=0;n<Sp_totalsprites;n++){
		mysprite[n].setImage("../images/msi0.gif",32,32,6,1);
		mysprite[n].setFrame(1+(Math.floor(Math.random()*4)))
	}
}

</script>
</head>
<body bgcolor="#000000" onload="init()" style="overflow:hidden">
<font color="#ffbb00" face="Arial" size=3>
<u>Mouse library example 1</u><br><br>
<font size=2>
When your mouse moves over a tile it will turn white,<br>
and when it moves off a tile, it will turn blue.<br><br>
Click on the tiles to stop and start them, and drag<br>
them around too!
</font>
</font>

</body>
</html>